package com.fowo.api.walmart.controller;

import cn.hutool.core.date.DateUtil;
import com.fowo.api.walmart.api.WalmartApi;
import com.fowo.api.walmart.api.WalmartInventoryApi;
import com.fowo.api.walmart.api.WalmartShipmentApi;
import com.fowo.api.walmart.entity.GetOrderDto;
import com.fowo.api.walmart.service.SyncWalmartOrderServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;

@RestController
@RequestMapping("/sync-walmart")
public class SyncWalmartController {

    @Resource
    private SyncWalmartOrderServiceImpl walmartOrderService;
    @Resource
    private WalmartApi walmartApi;
    @Resource
    private WalmartShipmentApi walmartShipmentApi;
    @Resource
    private WalmartInventoryApi walmartInventoryApi;


//    @PostMapping("/order")
//    public void syncOrder(){
//        GetOrderDto getOrderDto = new GetOrderDto();
//        walmartOrderService.syncOrder();
//    }
    @PostMapping("/item")
    public void syncItem() throws Exception {
        walmartOrderService.syncItem();
    }

    @PostMapping("/shipment")
    public void syncShipment() throws Exception {
        GetOrderDto getOrderDto = new GetOrderDto();
//        getOrderDto.setCreatedStartDate(DateUtil.formatDate(DateUtil.yesterday()));
//        getOrderDto.setCreatedEndDate(DateUtil.formatDate(DateUtil.yesterday()));
        getOrderDto.setLastModifiedStartDate(DateUtil.formatDate(DateUtil.yesterday()));
        getOrderDto.setLastModifiedEndDate(DateUtil.formatDate(new Date()));
        getOrderDto.setProductInfo("true");
        walmartApi.getOrder(getOrderDto);
    }

    @PostMapping("/inventory")
    public void syncInventory() throws IOException {
        walmartOrderService.syncInventory();
    }
}
